package cn.waka.sys.admin.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.waka.sys.admin.dao.FaceDao;
import cn.waka.sys.admin.object.Page;

@Service
public class FaceService {

    @Autowired
    private FaceDao faceDao;

    public Page findPage(Page p, Map<String, String> param) {
        List<Map<String, Object>> list = faceDao.findList(p, param);
        int count = faceDao.findCount(p, param);
        p.setData(list);
        p.setCount(count);
        int totalCount = 1;
        if (count % p.getSize() > 0) {
            totalCount = (int) Math.floor(count / p.getSize());
            totalCount++;
        } else {
            totalCount = count / p.getSize();
        }
        p.setTotalPage(totalCount);
        return p;
    }

    public Map<String, Object> findById(int id) {
        return faceDao.findById(id);
    }

    public int save(int id, String url, String description) {
        int rs = 1;
        if (id > 0) {
            rs = faceDao.update(id, url, description);
        } else {
            rs = faceDao.insert(url, description);
        }
        return rs;
    }

    public String findNewUrl() {
        return faceDao.findNewUrl();
    }

    public int del(int id) {
        return faceDao.del(id);
    }
}
